﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_AddTaskToSchedule]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_AddTaskToSchedule];
GO
CREATE PROCEDURE [dbo].[sproc_AddTaskToSchedule]
(
    @TaskID           int,
    @PeriodID         int,
    @Username      nvarchar(20),
    @Date              datetime,
    @IsConfirm       bit
  )
AS
    -- 不显示count信息
    SET NOCOUNT ON
    DECLARE @CurrentError int
    
    --  事务开始
    BEGIN TRANSACTION

    INSERT INTO UDS_Schedule(TaskID,PeriodID,Username,Date,IsConfirm)
    VALUES (@TaskID,@PeriodID,@Username,@Date,@IsConfirm)
    
   
    
    select @CurrentError = @@Error
    IF @CurrentError != 0
        BEGIN
               GOTO ERROR_HANDLER
        END

  
-- 事务结束
    COMMIT TRANSACTION
    -- 重设Count
    SET NOCOUNT OFF
    -- 成功的话返回0
    RETURN 0
  ERROR_HANDLER:
        ROLLBACK TRANSACTION
        SET NOCOUNT OFF
        RETURN @CurrentError